﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex03.GarageLogic
{
    /// <summary>
    /// Car is a class that inherit <see cref="Ex03.GarageLogic.Vehicle" />  and have also the properties:
    /// 1. Color
    /// 2. Number of doors
    /// </summary>
    internal class Car : Vehicle
    {
        private enum eColor 
        {
            Red,
            Yellow,
            Black,
            White,
            Blue
        }

        private enum eNumberOfDoors
        {
            Two = 2,
            Three = 3,
            Four = 4,
            Five = 5
        }

        private eColor m_ColorOfTheCar;
        private eNumberOfDoors m_NumberOfDoors;
        
        public Car(string i_VehicleModelName, string i_VehicleLicenseNumber, Wheel[] i_WheelsArary, EnergySource i_EnergySource)
            : base(i_VehicleModelName, i_VehicleLicenseNumber, i_WheelsArary, i_EnergySource)
        {
        }

        /// <summary>
        /// Overriding <see cref="Object.ToString"/>
        /// </summary>
        /// <returns>All the info of the Car formatted as on string</returns>
        public override string ToString()
        {
            string toString = string.Empty;
            
            toString = string.Format(@"
{0}
Color: {1}
Number of doors: {2}"
                , base.ToString()
                , m_ColorOfTheCar
                , m_NumberOfDoors);

            return toString;
        }

        /// <summary>
        /// Overriding <see cref="GarageLogic.Vehicle.GetSpecificProperties"/>
        /// </summary>
        /// <returns> List of strings that represnts messages for the Ui </returns>
        public override List<string> GetSpecificProperties()
        {
            string colorMessage;
            string numberOfDoorsMessage;
            List<string> listOfspecificProperties = new List<string>();

            colorMessage = GetPropertyMessageOfEnum("Enter Car Colors from:", typeof(eColor));
            listOfspecificProperties.Add(colorMessage.ToString());
            numberOfDoorsMessage = GetPropertyMessageOfEnum("Enter Car Colors from:", typeof(eNumberOfDoors));
            listOfspecificProperties.Add(numberOfDoorsMessage.ToString());
                      
            return listOfspecificProperties;
        }

        /// <summary>
        /// Overriding <see cref="GarageLogic.Vehicle.SetSpecificProperties"/> sets in Car his specific properties
        /// </summary>
        /// <param name="i_ListOfSpecificVehiclePropertiesFromUser">List of user inputs from the UI </param>
        public override void SetSpecificProperties(List<string> i_ListOfSpecificVehiclePropertiesFromUser)
        {
            eColor colorParseResult = 0;
            eNumberOfDoors NumberOfDoorsParseResult = 0;
            const bool v_CaseSensitive = true;
            bool isParseCorrect = false;

            isParseCorrect = Enum.TryParse(i_ListOfSpecificVehiclePropertiesFromUser[0], v_CaseSensitive, out colorParseResult);
            isParseCorrect = Enum.IsDefined(typeof(eColor), colorParseResult);
            if (isParseCorrect)
            {
                m_ColorOfTheCar = colorParseResult;
            }
            else
	        {
                throw new FormatException("color is not supported");
	        }

            isParseCorrect = Enum.TryParse(i_ListOfSpecificVehiclePropertiesFromUser[1], v_CaseSensitive, out NumberOfDoorsParseResult);
            isParseCorrect = Enum.IsDefined(typeof(eNumberOfDoors), NumberOfDoorsParseResult);
            if (isParseCorrect)
            { 
                m_NumberOfDoors = NumberOfDoorsParseResult;
            }
            else
	        {
                throw new FormatException("number of doors is not supported");
	        }       
        }
    }
}
